package cn.wk.servlet;

import cn.wk.entity.Admins;
import cn.wk.entity.Stuinfo;
import cn.wk.entity.Teacher;
import cn.wk.services.AdminsServices;
import cn.wk.services.StuinfoServices;
import cn.wk.services.TeacherServices;
import cn.wk.services.impl.AdminsServicesImpl;
import cn.wk.services.impl.StuinfoServicesImpl;
import cn.wk.services.impl.TeacherServicesImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/userManager")
public class ServletuserManager extends HttpServlet {
    private AdminsServices as=new AdminsServicesImpl();
    private TeacherServices ts=new TeacherServicesImpl();
    private StuinfoServices ss=new StuinfoServicesImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String roel=request.getParameter("roel");
        String no=request.getParameter("no");
        if(roel.equals("管理员")){
            Admins admin=as.findAdminByNo(no);
            request.setAttribute("admin",admin);
            request.setAttribute("cool","cool");
            request.getRequestDispatcher("/admins-add.jsp").forward(request,response);
        }else if(roel.equals("教师")){
            Teacher teacher=ts.findAdminByNo(no);
            request.setAttribute("teacher",teacher);
            request.setAttribute("cool","cool");
            request.getRequestDispatcher("/teacher-add.jsp").forward(request,response);

        }else if(roel.equals("学生")){
            Stuinfo stuinfo=ss.findStuinfoByNo(no);
            request.setAttribute("stuinfo",stuinfo);
            request.setAttribute("cool","cool");
            request.getRequestDispatcher("/stuinfo-add.jsp").forward(request,response);
        }
    }
}
